package se.ytterman.jserial.util;

import se.ytterman.jserial.net.*;
import java.lang.*;
import java.io.*;
import java.util.*;
import java.net.*;

import se.ytterman.jserial.io.CommunicationAdapter;

public class DummyServerInterface implements CommunicationAdapter {
    // 
    public DummyServerInterface() {
        // Assign streams...
        this.inputStream = System.in;
        this.outputStream = System.out;
    }
    
    // Read from serial interface
    public byte[] read() {
        // 
        byte[] result = null;
        
        try {
            // Read from socket...
            byte[] buffer = new byte[1024];
            int bytes = this.inputStream.read(buffer);
            
            // Copy and truncate
            result = Arrays.copyOf(buffer, bytes);
        }
        catch(Exception e) {
            System.out.println("InputStream.read(): " + e.getMessage());
        }
        
        return result;
    }

    // Write to serial interface
    public void write(byte[] data) {
        try {
            this.outputStream.write(data);
        }
        catch(Exception e) {
            System.out.println("OutputStream.write(): " + e.getMessage());
        };
    }
    
    // Define adapter streams...
    private InputStream inputStream;
    private OutputStream outputStream;
}
